/*******************************************************************************
  * Copyright(c) 2023 Levetop Semiconductor Co.,Led. All rights reserved.   
  * @file     function.h
  * @author   UartTFT Application Team
  * @version  V0.0.1
  * @date     2023-01-05
  * @brief    
********************************************************************************/ 

#ifndef _FUNCTION_H
#define _FUNCTION_H

#include "data.h"

/* LCD color */
#define White          0xFFFF
#define Black          0x0000
#define Grey           0xF7DE
#define Blue           0x001F
#define Blue2          0x051F
#define Red            0xF800
#define Magenta        0xF81F
#define Green          0x07E0
#define Cyan           0x7FFF
#define Yellow         0xFFE0

//Color Transform
uint16_t LT_Color24_To_16(uint32_t color);

void LT268_TFT_DrawPoint(uint16_t x,uint16_t y,uint16_t color);
void LT268_TFT_FillColor(uint16_t x,uint16_t y,uint16_t Width,uint16_t High,uint16_t color);

void LT268_TFT_Draw_hline(uint16_t x0,uint16_t y0,uint16_t len,uint16_t color);
void LT268_TFT_Draw_vline(uint16_t x0,uint16_t y0,uint16_t len,uint16_t color);

void LT268_TFT_DrawLine(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2,uint16_t color);
void LT268_TFT_DrawLine_Width(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2,uint16_t color,uint16_t Width);

void LT268_TFT_DrawSquare(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2,uint16_t color);
void LT268_TFT_DrawSquare_Fill(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2,uint16_t color);
void LT268_TFT_DrawSquare_Width(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2,uint16_t WidthColor,uint16_t BackgroundColor,uint16_t Width);

void LT268_TFT_DrawCircleSquare(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2,uint8_t r,uint16_t color);
void LT268_TFT_DrawCircleSquare_Fill(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2,uint8_t r,uint16_t color);
void LT268_TFT_DrawCircleSquare_Width(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2,uint8_t r,uint16_t WidthColor,uint16_t BackgroundColor,uint16_t Width);

void _draw_circle_8(int32_t xc, int32_t yc, int32_t x, int32_t y, uint16_t color);
void LT268_TFT_DrawCircle(uint16_t xc, uint16_t yc, uint16_t r, uint16_t color);
void LT268_TFT_DrawCircle_Fill(uint16_t xc,uint16_t yc,uint16_t r,uint16_t color);
void LT268_TFT_DrawCircle_Width(uint16_t xc, uint16_t yc, uint16_t r,uint16_t WidthColor,uint16_t BackgroundColor,uint16_t Width);

void LT268_TFT_Draw_expoint(uint16_t sx,uint16_t sy,uint16_t ex,uint16_t ey,uint16_t x,uint16_t y,uint16_t color);
void gui_draw_circle8(uint16_t sx,uint16_t sy,uint16_t ex,uint16_t ey,uint16_t rx,uint16_t ry,int32_t a,int32_t b,uint16_t color);
void gui_draw_arc(uint16_t sx,uint16_t sy,uint16_t ex,uint16_t ey,uint16_t rx,uint16_t ry,uint16_t r,uint16_t color,uint8_t mode);

void LT268_TFT_DrawEllipse(uint16_t x0, uint16_t y0, uint16_t rx, uint16_t ry,uint16_t color);
void LT268_TFT_DrawEllipse_Fill(uint16_t x0,uint16_t y0,uint16_t rx,uint16_t ry,uint16_t color);
void LT268_TFT_DrawEllipse_Width(uint16_t x0, uint16_t y0, uint16_t rx,uint16_t ry,uint16_t WidthColor,uint16_t BackgroundColor,uint16_t Width);

void LT268_TFT_DrawTriangle(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2,uint16_t x3,uint16_t y3,uint16_t color);
void LT268_TFT_DrawTriangle_Fill(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2,uint16_t x3,uint16_t y3,uint16_t color);
void LT268_TFT_DrawTriangle_Frame(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2,uint16_t x3,uint16_t y3,uint16_t WidthColor,uint16_t BackgroundColor);

uint8_t LT268_TFT_DrawCylinder(uint16_t XCenter,uint16_t YCenter,uint16_t X_R,uint16_t Y_R,uint16_t H,uint32_t CylinderColor,uint32_t ForegroundColor,uint8_t Width);

void LT268_TFT_MakeTable(uint16_t X1,uint16_t Y1,uint16_t W,uint16_t H,uint16_t Line,uint16_t Row,uint32_t  TableColor,uint32_t  ItemColor,uint32_t  ForegroundColor,uint16_t width1,uint16_t width2,uint8_t  mode);


//font display
void LT268_TFT_Show_Internal_Char(uint16_t x,uint16_t y,uint8_t size_w,uint8_t size_h,uint8_t disp_w,uint8_t mode,uint16_t FontColor,uint16_t BackGroundColor,uint8_t num);
void LT268_TFT_ShowAscll(uint16_t x,uint16_t y,uint8_t size,uint8_t mode,uint16_t FontColor,uint16_t BackGroundColor,uint8_t *str);

void LT268_GrayScaleFont_dislay(uint8_t type, uint8_t layn,uint32_t addr,uint8_t font_w,uint8_t font_h,uint8_t gray,
	uint16_t FColor,uint16_t BColor,uint8_t enbackcolor,uint8_t mix,_PICINFO mixpic,
	uint16_t tft_x,uint16_t tft_y,uint16_t disp_w,uint8_t *c,uint16_t buff_w);

void LT268_GrayScaleFont_dislay_BUFF(uint8_t type,uint32_t addr,uint8_t font_w,uint8_t font_h,uint8_t gray,
	uint16_t FColor,uint16_t BColor,uint8_t enbackcolor,uint16_t disp_w,uint8_t *c,
	uint16_t buf_x,uint16_t buf_y,uint16_t buf_w,uint8_t *buf);

//RGB color scale
void disp_V_Gray(void);        

/*Buffer model*/
void LT268_TFT_DrawPoint_Buffer(uint16_t x,uint16_t y,uint16_t color,uint16_t canvas_w);

void LT268_TFT_FillColor_Buffer2(uint16_t buf_x,uint16_t buf_y,uint16_t buf_w,uint8_t* m_Data,uint16_t Width,uint16_t High,uint16_t color);

void LT268_TFT_Draw_hline_Buffer(uint16_t x0,uint16_t y0,uint16_t len,uint16_t color,uint16_t canvas_w);

void LT268_TFT_DrawLine_Buffer(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2,uint16_t color,uint16_t canvas_w);
void LT268_TFT_DrawLine_Width_Buffer(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2,uint16_t color,uint16_t Width,uint16_t canvas_w);

void LT268_TFT_DrawSquare_Fill_Buffer(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2,uint16_t color,uint16_t canvas_w);

void LT268_TFT_DrawCircle_Fill_Buffer(uint16_t xc,uint16_t yc,uint16_t r,uint16_t color,uint16_t canvas_w);

void LT268_DrawTriangle_Fill_Buffer(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2,uint16_t x3,uint16_t y3,uint16_t color,uint16_t canvas_w);

void lineSDFAABB_BUFF(float ax, float ay, float bx, float by, float r,uint32_t color,uint16_t canvas);

/*Buffer model with alphablend*/
void LT268_DrawPoint_Buffer_alphablend(int32_t x, int32_t y, float alpha, uint32_t color, uint16_t canvas);

uint8_t line_k_compare(uint16_t x0,uint16_t y0,uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2);
float line_k(float x0, float y0, float x1, float y1);


uint8_t GetOverlapPart_rect(uint16_t x1, uint16_t y1, uint16_t w1, uint16_t h1, uint16_t *x, uint16_t *y, uint16_t *w, uint16_t *h);

void DrawClockPointer(
uint16_t H_x, uint16_t H_y, uint16_t H_angle, uint16_t H_lenL, uint16_t H_lenS, uint32_t H_color, uint8_t H_r,
uint16_t M_x, uint16_t M_y, uint16_t M_angle, uint16_t M_lenL, uint16_t M_lenS, uint32_t M_color, uint8_t M_r,
uint16_t S_x, uint16_t S_y, uint16_t S_angle, uint16_t S_lenL, uint16_t S_lenS, uint32_t S_color, uint8_t S_r,
uint16_t P_x, uint16_t P_y, uint16_t P_w, uint16_t P_h
);

#endif /* _FUNCTION_H */
